<template>
  <div class="container">
    <div class="topSearch">
      <div class="form">
        <el-form
          ref="form"
          :model="fileParams"
          label-width="10px"
          class="formSelf"
        >
          <el-form-item>
            <el-input
              placeholder="文件名称"
              v-model="fileParams.fileName"
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-button class="search" icon="el-icon-search" @click="searchForm"
              >查询</el-button
            >
            <el-button
              class="reset"
              icon="el-icon-refresh-right"
              @click="resetForm"
              >重置</el-button
            >
            <el-button class="search" icon="el-icon-plus" @click="addFile"
              >新增</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>

    <div class="tableBox">
      <div class="tableTitle"></div>
      <el-table v-loading="loading" :data="fileData" style="width: 100%">
        <el-table-column prop="fileName" label="文件名称"> </el-table-column>
        <el-table-column prop="fileTime" label="发布时间"> </el-table-column>

        <el-table-column prop="fileCompany" label="发布单位"> </el-table-column>
        <el-table-column prop="fileView" label="可查看单位"> </el-table-column>
        <el-table-column prop="remark" label="备注"> </el-table-column>

        <el-table-column prop="filePath" label="附件">
          <template slot-scope="scope">
            <div v-for="item in scope.row.filePath" :key="item.id">
              <el-link :href="item.filePath" target="_blank"
                >{{ item.fileName }};
              </el-link>
            </div>
          </template>
        </el-table-column>

        <el-table-column align="center" prop="address" label="操作">
          <template slot-scope="scope">
            <div class="btnBox">
              <div
                slot="reference"
                class="first"
                v-permission="'problemRegisterDetail'"
                @click="addFile(scope.row)"
              >
                修改
              </div>
              <div
                slot="reference"
                class="first"
                v-permission="'problemRegisterDetail'"
                @click="deleteVehicle(scope.row)"
              >
                删除
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="footerPage">
      <el-pagination
        :current-page="fileParams.page"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="10"
        layout="total, sizes, prev, pager, next"
        :total="fileTotal"
        @size-change="handleSizeChange"
        @current-change="currentPage"
      />
    </div>

    <addFile
      :addDialog.sync="addDialog"
      :dialogId="dialogId"
      ref="addFileRef"
    ></addFile>
  </div>
</template>

<script>
import addFile from "./addFile";
import { fileUploadPageApi, fileUpdate } from "@/api/fileUpload";

export default {
  name: "fireTable",
  props: {},
  components: {
    addFile,
  },
  data() {
    return {
      fileData: [],
      fileParams: {
        page: 1,
        pageSize: 10,
        fileName: "",
      },
      fileTotal: null,
      addDialog: false,
      dialogId: null,
      detailDialog: false,
      problemDetailRef: null,
      addFileRef: null,
      loading: true,
    };
  },
  created() {
    this.firePage();
  },
  methods: {
    searchForm() {
      this.fileParams.page = 1;
      this.firePage();
    },
    resetForm() {
      this.fileParams = {
        page: 1,
        pageSize: 10,
        fileName: "",
      };
      this.firePage();
    },
    addFile(row) {
      if (row.id) {
        this.$refs.addFileRef.form = row;
        this.$refs.addFileRef.fileList = row.filePath;
        this.$refs.addFileRef.uploaderSubmit = row.filePath;
        this.$refs.addFileRef.form.fileView = !Array.isArray(row.fileView)
          ? row.fileView.split(",")
          : row.fileView;
      }
      this.addDialog = true;
    },
    currentPage(val) {
      this.fileParams.page = val;
      this.firePage();
    },
    handleSizeChange(val) {
      this.fileParams.pageSize = val;
      this.firePage();
    },
    async firePage() {
      const res = await fileUploadPageApi({
        page: this.fileParams.page,
        pageSize: this.fileParams.pageSize,
        fileName: this.fileParams.fileName,
      });
      this.fileTotal = res.data.records.total;
      this.fileData = res.data.records;
      this.loading = false;
    },
    deleteVehicle(row) {
      this.$confirm(`此操作将永久删除   ${row.fileName}, 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const res = await fileUpdate({ id: row.id, delFlag: 1 });
          if (res.code == 0) {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          }
          this.firePage();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  mounted() {},
  watch: {},
  computed: {},
  filters: {},
};
</script>

<style scoped lang="scss">
.container {
  .topSearch {
    background-color: #fff;
    height: 68px;
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    .formSelf {
      display: flex;
      align-items: center;
      height: 68px;
      display: flex;
      align-items: center;
      .el-form-item {
        margin-bottom: 0px;
      }
      .search {
        background-color: #249451;
        color: #fff;
      }
      .reset {
        color: #249451;
        border: 1px solid #249451;
      }
      ::v-deep.el-input__inner {
        // background-color: #F5F5FA !important;
        color: #333 !important;
      }
      .el-input {
        width: 150px;
      }
      .el-select {
        width: 150px;
      }
    }
  }
  .tableBox {
    padding: 0 20px;
    background-color: #fff;
    .scopeImg {
      width: 50px;
      height: 50px;
    }
    .btnBox {
      display: flex;
      justify-content: center;
      align-items: center;
      .first {
        // width: 25px;
        height: 25px;
        line-height: 25px;
        // background-color: #4285f4;
        padding: 0 5px;
        color: #249451;
        text-align: center;
        border-radius: 5px;
        cursor: pointer;
      }
      .second {
        // width: 100px;
        height: 25px;
        line-height: 25px;
        background-color: #4285f4;
        color: #fff;
        text-align: center;
        margin-left: 5px;
        border-radius: 5px;
        cursor: pointer;
      }
      .third {
        // width: 50px;
        height: 25px;
        line-height: 25px;
        background-color: #d72e2e;
        color: #fff;
        text-align: center;
        margin: 0 5px;
        border-radius: 5px;
        cursor: pointer;
      }
      .third2 {
        width: 50px;
        height: 25px;
        line-height: 25px;
        background-color: #4285f4;
        color: #fff;
        text-align: center;
        margin: 0 5px;
        border-radius: 5px;
        cursor: pointer;
      }
      .last {
        width: 25px;
        height: 25px;
        line-height: 25px;
        background-color: #d72e2e;
        color: #fff;
        text-align: center;
        border-radius: 5px;
        cursor: pointer;
      }
    }
    .redC {
      color: #ff3057;
    }
    .yellowC {
      color: #ffd321;
    }
  }
  .footerPage {
    padding: 0 30px 0 0;
    display: flex;
    justify-content: right;
    width: 100%;
    background-color: #f8fafc;
    height: 50px;
    align-items: center;
    margin-top: 10px;

    //  ::v-deep .el-pagination .btn-next, .el-pagination .btn-prev{
    //   background-color: #087 !important;
    // }
  }
}
</style>
